# 练习11:自己实现一个shutil.rmtree函数
import os

def rmtree(path):
    if os.path.isfile(path):
        os.remove(path)
    elif os.path.isdir(path):
        for item in os.listdir(path):
            subpath = os.path.join(path, item)
            rmtree(subpath)
        os.rmdir(path)
    else:
        raise ValueError(f"Invalid path: {path}")

# 示例
directory_to_delete = "path_to_directory"
rmtree(directory_to_delete)

